A = double(imread('yellowlily.jpg'));
figure,imshow(imread('yellowlily.jpg')),title('Original Image');
[m,n] = size(A(:,:,1));
RGB = zeros(size(A));
[ur sr vr] = svd(A(:,:,1));
[ug sg vg] = svd(A(:,:,2));
[ub sb vb] = svd(A(:,:,3));
k = input('Enter the number of components ');
for i = 1:k
   RGB(:,:,1) = RGB(:,:,1) +(sr(i,i)*ur(:,i)*vr(:,i).');
   RGB(:,:,2) = RGB(:,:,2) +(sg(i,i)*ug(:,i)*vg(:,i).');
   RGB(:,:,3) = RGB(:,:,3) +(sb(i,i)*ub(:,i)*vb(:,i).');
end
cr = m*n/(k*(m+n+1));
disp(['Compression Ratio is : ',num2str(cr)]);
figure,imshow(uint8(RGB)),title('Compressed Image');
